package gameressources;

import java.util.ArrayList;
import java.util.List;

import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;

public class Main {
	private RockPaperScissors RPS;

	 @DataProvider(name = "win")
	 public Object[][] createWinData()
	 {
		 return new Object [][]{
				 {RPSEnum.ROCK,RPSEnum.SCISSORS}
		 };
		 
	 }
	 @DataProvider(name = "lost")
	 public Object[][] createLostData()
	 {
		 return new Object [][]{
				 {RPSEnum.PAPER,RPSEnum.SCISSORS}
		 };
		 
	 }
	 @DataProvider(name = "tie")
	 public Object[][] createTieData()
	 {
		 return new Object [][]{
				 {RPSEnum.ROCK,RPSEnum.ROCK}
		 };
		 
	 }
	 
	 @DataProvider(name = "p1win")
	 public Object[][] createWinDataList()
	 {	
		 List<RPSEnum> listplayer1 = new ArrayList<RPSEnum>();
		 List<RPSEnum> listplayer2 =new ArrayList<RPSEnum>();
		 for(int i=0;i<10;i++)
		 {
			 listplayer1.add(RPSEnum.PAPER);
			 listplayer2.add(RPSEnum.ROCK);
		 }
		 return new Object [][]{
				 {new Player("p1",0, listplayer1),new Player("p2",0, listplayer2)}
		 };
		 
	 }
	 @DataProvider(name = "p1lost")
	 public Object[][] createLostDataList()
	 {
		 List<RPSEnum> listplayer1 = new ArrayList<RPSEnum>();
		 List<RPSEnum> listplayer2 =new ArrayList<RPSEnum>();
		 for(int i=0;i<10;i++)
		 {
			 listplayer2.add(RPSEnum.PAPER);
			 listplayer1.add(RPSEnum.ROCK);
		 }
		 return new Object [][]{
				 {new Player("p1",0, listplayer1),new Player("p2",0, listplayer2)}
		 };
		 
	 }
	 @DataProvider(name = "p1tie")
	 public Object[][] createTieDataList()
	 {
		 List<RPSEnum> listplayer1 = new ArrayList<RPSEnum>();
		 List<RPSEnum> listplayer2 =new ArrayList<RPSEnum>();
		 for(int i=0;i<10;i++)
		 {
			 listplayer1.add(RPSEnum.PAPER);
			 listplayer2.add(RPSEnum.PAPER);
		 }
		 return new Object [][]{
				 {new Player("p1",0, listplayer1),new Player("p2",0, listplayer2)}
		 };
		 
	 }
  
  @Test	(dataProvider="win")
	void testWinPlay(RPSEnum player1, RPSEnum player2) {

		Assert.assertEquals(RPS.play(RPSEnum.valueOf(player1.toString()), RPSEnum.valueOf(player2.toString())),Result.WIN);
	}
  

  @Test	(dataProvider="tie")
	void testTiePlay(RPSEnum player1, RPSEnum player2) {
	  Assert.assertEquals(RPS.play(RPSEnum.valueOf(player1.toString()), RPSEnum.valueOf(player2.toString())),Result.TIE);

	}

  @Test	(dataProvider="lost")
	void testLostPlay(RPSEnum player1, RPSEnum player2) {
	  Assert.assertEquals(RPS.play(RPSEnum.valueOf(player1.toString()), RPSEnum.valueOf(player2.toString())),Result.LOST);

	}
  
  @Test	(dataProvider="player1 win")
 	void testWinPlayList(Player player1, Player player2) {
 		Assert.assertEquals(RPS.play(player1, player2),Result.WIN);
 	}
   

   @Test (dataProvider="player1 tie")
 	void testTiePlayList(Player player1, Player player2) {
	   Assert.assertEquals(RPS.play(player1, player2),Result.TIE);

 	}

   @Test (dataProvider="player1 lost")
 	void testLostPlayList(Player player1, Player player2) {
	   Assert.assertEquals(RPS.play(player1, player2),Result.LOST);

 	}
  
  
  @BeforeClass
	void setUpClass() {

		RPS = new RockPaperScissors();
	}

  @AfterClass
  public void afterClass() {
	  RPS = null;
  }

}
